package com.lbssoft.gpsbd.controller;

import com.lbssoft.gpsbd.model.Config;
import com.lbssoft.gpsbd.model.Result;
import com.lbssoft.gpsbd.service.ConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@Api("系统配置")
@RestController
@RequestMapping(value="/config")
public class ConfigController {

	@Autowired
	ConfigService configService;

	@ApiOperation(value="获取配置信息", notes="获取配置信息")
	@RequiresPermissions("system:config:view")
	@RequestMapping(value = "",method = {RequestMethod.GET})
	public Result getConfig(){
		Result result = new Result();
		Config config = configService.getConfig();
		result.setData(config);
		return result;
	}

	@ApiOperation(value="获取注册配置信息", notes="获取注册配置信息")
	@RequestMapping(value = "/register",method = {RequestMethod.GET})
	public Result getConfigByReg(){
		Result result = new Result();
		Config config = configService.getConfig();
		result.setData(config.isRegistration());
		return result;
	}

	@ApiOperation(value="获取地图配置", notes="获取地图配置")
	@RequestMapping(value = "/maps",method = {RequestMethod.GET})
	public Result getConfigByMaps(){
		Result result = new Result();
		Config config = configService.getConfig();
		result.setData(config.getMaps());
		return result;
	}

	@ApiOperation(value="修改配置", notes="修改配置")
	@RequiresPermissions("system:config:update")
	@RequestMapping(value = "",method = {RequestMethod.PUT})
	public Result update(@RequestBody Config config){
		Result result = new Result();
		configService.update(config);
		result.setData(config);
		return result;
	}
	
	
	
}